<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\JingpinKecheng;

/**
 * JingpinKechengSearch represents the model behind the search form about `app\models\JingpinKecheng`.
 */
class JingpinKechengSearch extends JingpinKecheng
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['name', 'xibie', 'sex', 'birthday', 'xueli', 'xuewei', 'biye', 'zhuanye', 'zhicheng', 'zhicheng_time', 'zhengshu', 'zhengshu_time', 'kecheng_name', 'lixiang_time', 'fuzeren', 'xiangmu_jibie', 'lixiang_jigou', 'beizhu'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = JingpinKecheng::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            //分页
            'pagination' => [
                'pageSize' => 10,
            ],
            //排序
            'sort'=>[
                'defaultOrder'=>[
                    'id'=>SORT_ASC,
                ]
            ]
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'birthday' => $this->birthday,
            'biye' => $this->biye,
            'zhicheng_time' => $this->zhicheng_time,
            'zhengshu_time' => $this->zhengshu_time,
            'lixiang_time' => $this->lixiang_time,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'xibie', $this->xibie])
            ->andFilterWhere(['like', 'sex', $this->sex])
            ->andFilterWhere(['like', 'xueli', $this->xueli])
            ->andFilterWhere(['like', 'xuewei', $this->xuewei])
            ->andFilterWhere(['like', 'zhuanye', $this->zhuanye])
            ->andFilterWhere(['like', 'zhicheng', $this->zhicheng])
            ->andFilterWhere(['like', 'zhengshu', $this->zhengshu])
            ->andFilterWhere(['like', 'kecheng_name', $this->kecheng_name])
            ->andFilterWhere(['like', 'fuzeren', $this->fuzeren])
            ->andFilterWhere(['like', 'xiangmu_jibie', $this->xiangmu_jibie])
            ->andFilterWhere(['like', 'lixiang_jigou', $this->lixiang_jigou])
            ->andFilterWhere(['like', 'beizhu', $this->beizhu]);

        return $dataProvider;
    }
}
